package com.ruoyi.costumeShop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.costumeShop.domain.Costume;
import com.ruoyi.costumeShop.service.ICostumeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * costumeController
 * 
 * @author ruoyi
 * @date 2022-04-05
 */
@RestController
@RequestMapping("/costumeShop/costume")
public class CostumeController extends BaseController
{
    @Autowired
    private ICostumeService costumeService;

    /**
     * 查询costume列表
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:costume:list')")
    @GetMapping("/list")
    public TableDataInfo list(Costume costume)
    {
        startPage();
        List<Costume> list = costumeService.selectCostumeList(costume);
        return getDataTable(list);
    }

    /**
     * 导出costume列表
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:costume:export')")
    @Log(title = "costume", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Costume costume)
    {
        List<Costume> list = costumeService.selectCostumeList(costume);
        ExcelUtil<Costume> util = new ExcelUtil<Costume>(Costume.class);
        util.exportExcel(response, list, "costume数据");
    }

    /**
     * 获取costume详细信息
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:costume:query')")
    @GetMapping(value = "/{costumeId}")
    public AjaxResult getInfo(@PathVariable("costumeId") Long costumeId)
    {
        return AjaxResult.success(costumeService.selectCostumeByCostumeId(costumeId));
    }

    /**
     * 新增costume
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:costume:add')")
    @Log(title = "costume", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Costume costume)
    {
        return toAjax(costumeService.insertCostume(costume));
    }

    /**
     * 修改costume
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:costume:edit')")
    @Log(title = "costume", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Costume costume)
    {
        return toAjax(costumeService.updateCostume(costume));
    }

    /**
     * 删除costume
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:costume:remove')")
    @Log(title = "costume", businessType = BusinessType.DELETE)
	@DeleteMapping("/{costumeIds}")
    public AjaxResult remove(@PathVariable Long[] costumeIds)
    {
        return toAjax(costumeService.deleteCostumeByCostumeIds(costumeIds));
    }
}
